﻿// (c) Copyright slimCODE Software Inc. - www.slimcode.com
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using SlimCode.Windows.Controls.Mobile;
using System.Drawing;

namespace SlimCode.SlimPasswords
{
  class PasswordInfoView : ItemView
  {
    public PasswordInfoView( string label, string text )
      : base( text, 2 )
    {
      this.Label = label ?? string.Empty;
    }

    public string Label { get; private set; }

    /*
    protected override Size GetPreferredSize( TemplatedPaintEventArgs args, Rectangle workingRect )
    {
      return this.Parent.ClientSize;
    }
    */

    protected override void DrawTopLayer( TemplatedPaintEventArgs e )
    {
      Rectangle rect = this.ClientRectangle;

      rect.Inflate( -5, -2 );

      if( string.IsNullOrEmpty( this.Label ) )
      {
        // Draw the text, centered.
        base.DrawTopLayer( e );
      }
      else
      {
        rect.Height /= 2;

        e.StringFormat.Alignment = StringAlignment.Near;
        e.StringFormat.LineAlignment = StringAlignment.Far;

        e.Graphics.DrawString(
          this.Label,
          e.SmallFont,
          e.ForegroundBrush,
          rect,
          e.StringFormat );

        rect.Y += rect.Height;

        e.StringFormat.LineAlignment = StringAlignment.Near;

        e.Graphics.DrawString(
          this.Text,
          e.NormalFont,
          e.ForegroundBrush,
          rect,
          e.StringFormat );
      }
    }
  }
}
